<?php

namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;

/**
* 
*/
class Member extends Model
{
	use SoftDelete;
	//关联评论
	public function content(){
		return $this->hasMany('Content','member_id','id');
	}
	
	//添加会员
	public function add($data){
		$validate=new \app\common\validate\Member();
		if(!$validate->scene('add')->check($data)){
			return $validate->getError();
		}
		$result=$this->allowField(true)->save($data);
		if($result){
			return 1;
		}else{
			return "会员添加失败！";
		}
	}

	//会员编辑
	public function edit($data){
		$validate=new \app\common\validate\Member();
		
		if(!$validate->scene('edit')->check($data)){
			return $validate->error();
		}
		$memberInfo=$this->find($data['id']);
		if($memberInfo['password']!=$data['oldpassword']){
			return '原密码不正确！';
		}
		$memberInfo->password=$data['newpassword'];
		$memberInfo->nickname=$data['nickname'];
		$memberInfo->email=$data['email'];
		$result=$memberInfo->save();
		if($result){
			return 1;
		}else{
			return "修改失败";
		}
	}
	

	
}